package com.mathdroid.model.enums;

import java.util.LinkedList;

import com.mathdroid.exceptionhandling.ParserException;

/**
 * Items of the type "Module" have different proficiencies.
 */
public enum EModuleProficiency {
	
	/**
	 * Emitter Matrix.
	 */
	EMITTER_MATRIX("Emitter Matrix"),
	/**
	 * Color Cartidage.
	 */
	COLOR_CARTIDGE("Color Cartidage"),
	/**
	 * General Power Crystal Proficiency.
	 */
	POWER_CRYSTAL("Power Crystal"),
	/**
	 * Power Crystal 1.
	 */
	POWER_CRYSTAL_1("Power Crystal 1"),
	/**
	 * Power Crystal 2.
	 */
	POWER_CRYSTAL_2("Power Crystal 2"),
	/**
	 * Hilt.
	 */
	HILT("Hilt"),
	/**
	 * Barrel.
	 */
	BARREL("Barrel"),
	/**
	 * Focus Lense.
	 */
	FOCUS_LENSE("Focus Lense"),
	/**
	 * Modulator.
	 */
	MODULATOR("Modulator"),
	/**
	 * Power Cell.
	 */
	POWER_CELL("Power Cell"),
	/**
	 * Scope.
	 */
	SCOPE("Scope"),
	/**
	 * Trigger.
	 */
	TRIGGER("Trigger"),
	/**
	 * Harness.
	 */
	HARNESS("Harness"),
	/**
	 * Circuitry.
	 */
	CIRCUITRY("Circuitry"),
	/**
	 * Overlay.
	 */
	OVERLAY("Overlay"),
	/**
	 * Support.
	 */
	SUPPORT("Support"),
	/**
	 * Underlay.
	 */
	UNDERLAY("Underlay");
	
	/**
	 * String representation of the proficiency.
	 */
	private String name = null;
	
	/**
	 * Create a new module type proficiency.
	 * @param n Name of the type.
	 */
	private EModuleProficiency(final String n) {
		this.name = n;
	}
	
	@Override	
	public String toString() {
		return this.name;
	}
	
	/**
	 * Get a list of all module types.
	 * @return Item modules.
	 */
	public static final 
	LinkedList<EModuleProficiency> getModuleProficiencies() {
		LinkedList<EModuleProficiency> modules = 
			new LinkedList<EModuleProficiency>();

		modules.add(EMITTER_MATRIX);
		modules.add(COLOR_CARTIDGE);
		modules.add(POWER_CRYSTAL);
		modules.add(POWER_CRYSTAL_1);
		modules.add(POWER_CRYSTAL_2);
		modules.add(HILT);
		modules.add(BARREL);
		modules.add(FOCUS_LENSE);
		modules.add(MODULATOR);
		modules.add(POWER_CELL);
		modules.add(SCOPE);
		modules.add(TRIGGER);
		modules.add(HARNESS);
		modules.add(CIRCUITRY);
		modules.add(OVERLAY);
		modules.add(SUPPORT);
		modules.add(UNDERLAY);
		
		return modules;
	}
	
	/**
	 * Parse a string to an enumeration object. The parser compares the
	 * string representation of this enumeration with the parameter, not the
	 * literal.
	 * @param s String.
	 * @return EModuleProficiency object.
	 * @throws ParserException The string cannot be parsed.
	 */
	public static final 
	EModuleProficiency parseEModuleProficiency(final String s) 
	throws ParserException {
		EModuleProficiency t = null;
		
		for (EModuleProficiency type 
				: EModuleProficiency.getModuleProficiencies()) {
			if (s.equals(type.toString())) {
				t = type;
			}
		}
		
		if (t == null) {
			ParserException p = new ParserException(
					"No such module proficiency: \"" + s + "\"");
			p.fillInStackTrace();
			throw p;
		}
		
		return t;
	}
}
